package com.koro.controller;

import com.koro.annotation.DataAccess;
import com.koro.dto.FindGoodsDTO;
import com.koro.dto.SaveGoodsDTO;
import com.koro.service.GoodsService;
import com.koro.vo.FindGoodsVO;
import com.koro.vo.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品管理")
@RequestMapping("/goods")
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "更新商品",notes = "更新商品")
    @PostMapping("/save")
    public ResponseObject<Integer> save(@RequestBody SaveGoodsDTO dto) {
        return ResponseObject.ok(goodsService.save(dto));
    }

    @ApiOperation(value = "分页查询商品",notes = "分页查询")
    @PostMapping("/findAll")
    public ResponseObject<List<FindGoodsVO>> findAll(@RequestBody FindGoodsDTO dto) {
        return ResponseObject.ok(goodsService.findAll(dto));
    }

    @ApiOperation(value = "商品详情",notes = "商品详情")
    @PostMapping("/findById")
    public ResponseObject<FindGoodsVO> findById(@RequestBody FindGoodsDTO dto) {
        return ResponseObject.ok(goodsService.findById(dto));
    }

    @ApiOperation(value = "更新秒杀商品",notes = "更新秒杀商品")
    @GetMapping("/updataseckill")
    public ResponseObject<Integer> updataseckill(@RequestParam("id") Integer id) {
        return ResponseObject.ok(goodsService.updataseckill(id));
    }
}
